package ebusiness.ebusiness.Controllers;

import ebusiness.ebusiness.Dao.UserDao.AdminQueryVO;
import ebusiness.ebusiness.Dao.UserDao.UserQueryVO;
import ebusiness.ebusiness.Entity.Address;
import ebusiness.ebusiness.Entity.UserEntity.User;
import ebusiness.ebusiness.Entity.UserEntity.UserDetail;
import ebusiness.ebusiness.Mapper.PathUtil.PagePath;
import ebusiness.ebusiness.Mapper.PathUtil.WebPath;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class ShowUserController {
    @RequestMapping(path = WebPath.ShowUSER,method = RequestMethod.GET)
    public String showUser(Model model) throws Exception{
        AdminQueryVO adminQueryVO = new AdminQueryVO();
        List<User> userList = null;
        try{
            userList = adminQueryVO.getUserByID();
            model.addAttribute("users",userList);
        }
        catch (Exception e){

        }
        return PagePath.SHOWUSER;

    }
    @RequestMapping(path = WebPath.PersonINFO,method = RequestMethod.GET)
    public String showPersonInfo(HttpSession session, Model model) throws Exception {
        int id = (int) session.getAttribute("user");

        if( id < 0 ){
            //未登录
            return "redirect:"+WebPath.LOGIN;
        }else {
            UserQueryVO userQueryVO = new UserQueryVO();
            UserDetail userDetail = userQueryVO.getUserDetailByID(id);
            List<Address> address = userQueryVO.getAddressByUser(id);
            model.addAttribute("personInfo",userDetail);
            model.addAttribute("address",address);
            return PagePath.SHOWUSER2;
        }
    }
}
